package com.example.demo.Util.redisUtil;

import com.example.demo.Util.Result;
import com.example.demo.Util.ResultUtil;

public abstract class RedisLockTemplate {

    public Result executeSafely(RedisService redisService, String requsetid, int courseid){
        boolean res =   redisService.TryGetLock(requsetid,courseid);
        if(!res) return ResultUtil.fail("稍后重试");

        try {
            return ActionInLock();
        }finally {
            redisService.UnLock(requsetid,courseid);
        }

    }

    public abstract Result ActionInLock();


}
